package com.huang.exception;

import com.huang.enums.ResultStatus;

public class ServiceException extends RuntimeException {

    private final ResultStatus status;

    private final Object[] args;

    public ServiceException(ResultStatus status, Object ...args) {
        this.status = status;
        this.args = args;
    }

    public ServiceException(ResultStatus status) {
        this.status = status;
        this.args = null;
    }

    public ResultStatus getStatus() {
        return status;
    }

    @Override
    public String getMessage() {
        return args == null ? status.getMsg() : String.format(status.getMsg(), args);
    }

    public Object[] getArgs() {
        return args;
    }
}
